package day04;


import java.util.Scanner;

public class CommandBySwitch {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请选择功能：1.存款 2.取款 3.查询余额 4.退卡");
        int command = scan.nextInt();
        double sum = 0, num;
        while (command <= 4)
            switch (command) {
                case 1:
                    System.out.println("请输入存款金额：");
                    num = scan.nextDouble();
                    sum += num;
                    System.out.println("存款成功存入：" + num + "元，您的账户余额为：" + sum);
                    System.out.println("1.继续存款 2.其他业务");
                    int exit = scan.nextInt();
                    if(exit<3 &&exit>0) {
                        switch (exit) {
                            case 1:
                                command = 1;
                                break;
                            case 2:
                                command = scan.nextInt();
                                break;
                        }
                    }
                    break;
                case 2:
                    System.out.println("请输入取款金额：");
                    num = scan.nextDouble();
                    sum = sum - num;
                    System.out.println("取款成功取出：" + num + "元，您的账户余额为：" + sum);
                    break;
                case 3:
                    System.out.println("您的账户余额为：" + sum);
                    break;
                case 4:
                    System.out.println("退卡成功");
                    break;
                default:
                    System.out.println("输入错误");
            }
    }
}

